using System.Collections;
using UnityEngine;

public class MeshResource
{
	public Mesh mesh;

	private string _name;

	private IEnumerator _unload;

	private bool _alwaisLoaded;

	private int _countReferences;

	public int CountReferences
	{
		get
		{
			return _countReferences;
		}
		set
		{
			_countReferences = value;
			if (_alwaisLoaded || !(BCWResourceManager.instance != null))
			{
				return;
			}
			if (_countReferences > 0)
			{
				BCWResourceManager.instance.unloadQueue.Remove(_name);
				if (_unload != null)
				{
					BCWResourceManager.instance.StopCoroutine(_unload);
					_unload = null;
				}
			}
			else if (_unload == null)
			{
				_unload = MeshUnloader();
				BCWResourceManager.instance.StartCoroutine(_unload);
			}
		}
	}

	public MeshResource(string str, bool alwaysLoaded = false)
	{
		_name = str;
		_alwaisLoaded = alwaysLoaded;
	}

	private IEnumerator MeshUnloader()
	{
		yield return new WaitForSeconds(10f);
		BCWResourceManager.instance.unloadQueue.Enqueue(_name);
		_unload = null;
	}
}
